package org.example.springboot.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PaginationConfig {
  /**
   * 注册 MyBatis-Plus 插件，必须包含分页拦截器
   */
  @Bean
  public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

    // 添加分页插件，指定数据库类型（如 MySQL、Oracle 等）
    PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);

    // 可选配置：设置最大单页限制，防止分页参数过大导致性能问题
    paginationInterceptor.setMaxLimit(1000L); // 最大每页 1000 条

    interceptor.addInnerInterceptor(paginationInterceptor);
    return interceptor;
  }
}

